﻿namespace Borg.Framework
{
    public class QueuePlugs
    {
        private readonly QueuePlugsAttribute _attr;
        private readonly SlotInfo _slot;

        public QueuePlugs(SlotInfo slot, QueuePlugsAttribute attr)
        {
            _slot = slot;
            _attr = attr;
            slot.Plugging += OnPlugging;
        }

        private void OnPlugging(object sender, CancelPlugEventArgs args)
        {
            if (Runtime.IsCompositionAllowed && _slot.PluggedPlugInfos.Count == _attr.Length)
                _slot.Unplug(_slot.PluggedPlugInfos[0]);
        }
    }
}

